<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="考生身份证号，外键关联 tb_candidate(id_number)" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入考生身份证号，外键关联 tb_candidate(id_number)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文化程度，外键关联 ck_education(id)" prop="culturalLevelId">
        <el-input
          v-model="queryParams.culturalLevelId"
          placeholder="请输入文化程度，外键关联 ck_education(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业证书编号" prop="graduationCertificateNo">
        <el-input
          v-model="queryParams.graduationCertificateNo"
          placeholder="请输入毕业证书编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业类型，外键关联 ck_graduation_type(id)" prop="graduationTypeId">
        <el-input
          v-model="queryParams.graduationTypeId"
          placeholder="请输入毕业类型，外键关联 ck_graduation_type(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业学校，外键关联 ck_school(id)" prop="schoolId">
        <el-input
          v-model="queryParams.schoolId"
          placeholder="请输入毕业学校，外键关联 ck_school(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业日期" prop="graduationDate">
        <el-date-picker clearable
          v-model="queryParams.graduationDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择毕业日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="职业类别，外键关联 ck_occupation(id)" prop="occupationId">
        <el-input
          v-model="queryParams.occupationId"
          placeholder="请输入职业类别，外键关联 ck_occupation(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作单位所在地" prop="workLocation">
        <el-input
          v-model="queryParams.workLocation"
          placeholder="请输入工作单位所在地"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作单位名称" prop="workUnitName">
        <el-input
          v-model="queryParams.workUnitName"
          placeholder="请输入工作单位名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参加工作日期" prop="employmentDate">
        <el-date-picker clearable
          v-model="queryParams.employmentDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择参加工作日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="区外考生居住地，外键关联 ck_outside_residence(id)" prop="outsideResidenceId">
        <el-input
          v-model="queryParams.outsideResidenceId"
          placeholder="请输入区外考生居住地，外键关联 ck_outside_residence(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报考军人服役地，外键关联 ck_military_service(id)" prop="militaryServiceId">
        <el-input
          v-model="queryParams.militaryServiceId"
          placeholder="请输入报考军人服役地，外键关联 ck_military_service(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报考类型，外键关联 ck_exam_type(id)" prop="examTypeId">
        <el-input
          v-model="queryParams.examTypeId"
          placeholder="请输入报考类型，外键关联 ck_exam_type(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="户籍所在地名称" prop="householdLocation">
        <el-input
          v-model="queryParams.householdLocation"
          placeholder="请输入户籍所在地名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考生特征，外键关联 ck_candidate_feature(id)" prop="candidateFeatureId">
        <el-input
          v-model="queryParams.candidateFeatureId"
          placeholder="请输入考生特征，外键关联 ck_candidate_feature(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招生类别，外键关联 ck_admission_category(id)" prop="admissionCategoryId">
        <el-input
          v-model="queryParams.admissionCategoryId"
          placeholder="请输入招生类别，外键关联 ck_admission_category(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报考层次，外键关联 ck_exam_level(id)" prop="examLevelId">
        <el-input
          v-model="queryParams.examLevelId"
          placeholder="请输入报考层次，外键关联 ck_exam_level(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报考科类，外键关联 ck_exam_subject(id)" prop="examSubjectId">
        <el-input
          v-model="queryParams.examSubjectId"
          placeholder="请输入报考科类，外键关联 ck_exam_subject(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报考学习地点，外键关联 ck_study_location(id)" prop="studyLocationId">
        <el-input
          v-model="queryParams.studyLocationId"
          placeholder="请输入报考学习地点，外键关联 ck_study_location(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学习形式，外键关联 ck_study_mode(id)" prop="studyModeId">
        <el-input
          v-model="queryParams.studyModeId"
          placeholder="请输入学习形式，外键关联 ck_study_mode(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报名点信息，外键关联 ck_exam_site(id)" prop="examSiteId">
        <el-input
          v-model="queryParams.examSiteId"
          placeholder="请输入报名点信息，外键关联 ck_exam_site(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮政编码" prop="postalCode">
        <el-input
          v-model="queryParams.postalCode"
          placeholder="请输入邮政编码"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报考志愿院校名称，外键关联 ck_exam_university(id)" prop="examUniversityId">
        <el-input
          v-model="queryParams.examUniversityId"
          placeholder="请输入报考志愿院校名称，外键关联 ck_exam_university(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="意向专业，外键关联 ck_major(id)" prop="majorId">
        <el-input
          v-model="queryParams.majorId"
          placeholder="请输入意向专业，外键关联 ck_major(id)"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="紧急联系电话" prop="emergencyContact">
        <el-input
          v-model="queryParams.emergencyContact"
          placeholder="请输入紧急联系电话"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['chengkao:CKregistration:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['chengkao:CKregistration:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['chengkao:CKregistration:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['chengkao:CKregistration:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="CKregistrationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="报名信息表主键" align="center" prop="id" />
      <el-table-column label="考生身份证号，外键关联 tb_candidate(id_number)" align="center" prop="idNumber" />
      <el-table-column label="文化程度，外键关联 ck_education(id)" align="center" prop="culturalLevelId" />
      <el-table-column label="毕业证书编号" align="center" prop="graduationCertificateNo" />
      <el-table-column label="毕业类型，外键关联 ck_graduation_type(id)" align="center" prop="graduationTypeId" />
      <el-table-column label="毕业学校，外键关联 ck_school(id)" align="center" prop="schoolId" />
      <el-table-column label="毕业日期" align="center" prop="graduationDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.graduationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="职业类别，外键关联 ck_occupation(id)" align="center" prop="occupationId" />
      <el-table-column label="是否参加工作" align="center" prop="isEmployed" />
      <el-table-column label="工作单位所在地" align="center" prop="workLocation" />
      <el-table-column label="工作单位名称" align="center" prop="workUnitName" />
      <el-table-column label="参加工作日期" align="center" prop="employmentDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.employmentDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="区外考生居住地，外键关联 ck_outside_residence(id)" align="center" prop="outsideResidenceId" />
      <el-table-column label="报考军人服役地，外键关联 ck_military_service(id)" align="center" prop="militaryServiceId" />
      <el-table-column label="报考类型，外键关联 ck_exam_type(id)" align="center" prop="examTypeId" />
      <el-table-column label="户籍所在地名称" align="center" prop="householdLocation" />
      <el-table-column label="考生特征，外键关联 ck_candidate_feature(id)" align="center" prop="candidateFeatureId" />
      <el-table-column label="招生类别，外键关联 ck_admission_category(id)" align="center" prop="admissionCategoryId" />
      <el-table-column label="报考层次，外键关联 ck_exam_level(id)" align="center" prop="examLevelId" />
      <el-table-column label="报考科类，外键关联 ck_exam_subject(id)" align="center" prop="examSubjectId" />
      <el-table-column label="报考学习地点，外键关联 ck_study_location(id)" align="center" prop="studyLocationId" />
      <el-table-column label="学习形式，外键关联 ck_study_mode(id)" align="center" prop="studyModeId" />
      <el-table-column label="报名点信息，外键关联 ck_exam_site(id)" align="center" prop="examSiteId" />
      <el-table-column label="邮政编码" align="center" prop="postalCode" />
      <el-table-column label="报考志愿院校名称，外键关联 ck_exam_university(id)" align="center" prop="examUniversityId" />
      <el-table-column label="意向专业，外键关联 ck_major(id)" align="center" prop="majorId" />
      <el-table-column label="紧急联系电话" align="center" prop="emergencyContact" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['chengkao:CKregistration:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['chengkao:CKregistration:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改考生报名信息对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="CKregistrationRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="考生身份证号，外键关联 tb_candidate(id_number)" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入考生身份证号，外键关联 tb_candidate(id_number)" />
        </el-form-item>
        <el-form-item label="文化程度，外键关联 ck_education(id)" prop="culturalLevelId">
          <el-input v-model="form.culturalLevelId" placeholder="请输入文化程度，外键关联 ck_education(id)" />
        </el-form-item>
        <el-form-item label="毕业证书编号" prop="graduationCertificateNo">
          <el-input v-model="form.graduationCertificateNo" placeholder="请输入毕业证书编号" />
        </el-form-item>
        <el-form-item label="毕业类型，外键关联 ck_graduation_type(id)" prop="graduationTypeId">
          <el-input v-model="form.graduationTypeId" placeholder="请输入毕业类型，外键关联 ck_graduation_type(id)" />
        </el-form-item>
        <el-form-item label="毕业学校，外键关联 ck_school(id)" prop="schoolId">
          <el-input v-model="form.schoolId" placeholder="请输入毕业学校，外键关联 ck_school(id)" />
        </el-form-item>
        <el-form-item label="毕业日期" prop="graduationDate">
          <el-date-picker clearable
            v-model="form.graduationDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择毕业日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="职业类别，外键关联 ck_occupation(id)" prop="occupationId">
          <el-input v-model="form.occupationId" placeholder="请输入职业类别，外键关联 ck_occupation(id)" />
        </el-form-item>
        <el-form-item label="工作单位所在地" prop="workLocation">
          <el-input v-model="form.workLocation" placeholder="请输入工作单位所在地" />
        </el-form-item>
        <el-form-item label="工作单位名称" prop="workUnitName">
          <el-input v-model="form.workUnitName" placeholder="请输入工作单位名称" />
        </el-form-item>
        <el-form-item label="参加工作日期" prop="employmentDate">
          <el-date-picker clearable
            v-model="form.employmentDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择参加工作日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="区外考生居住地，外键关联 ck_outside_residence(id)" prop="outsideResidenceId">
          <el-input v-model="form.outsideResidenceId" placeholder="请输入区外考生居住地，外键关联 ck_outside_residence(id)" />
        </el-form-item>
        <el-form-item label="报考军人服役地，外键关联 ck_military_service(id)" prop="militaryServiceId">
          <el-input v-model="form.militaryServiceId" placeholder="请输入报考军人服役地，外键关联 ck_military_service(id)" />
        </el-form-item>
        <el-form-item label="报考类型，外键关联 ck_exam_type(id)" prop="examTypeId">
          <el-input v-model="form.examTypeId" placeholder="请输入报考类型，外键关联 ck_exam_type(id)" />
        </el-form-item>
        <el-form-item label="户籍所在地名称" prop="householdLocation">
          <el-input v-model="form.householdLocation" placeholder="请输入户籍所在地名称" />
        </el-form-item>
        <el-form-item label="考生特征，外键关联 ck_candidate_feature(id)" prop="candidateFeatureId">
          <el-input v-model="form.candidateFeatureId" placeholder="请输入考生特征，外键关联 ck_candidate_feature(id)" />
        </el-form-item>
        <el-form-item label="招生类别，外键关联 ck_admission_category(id)" prop="admissionCategoryId">
          <el-input v-model="form.admissionCategoryId" placeholder="请输入招生类别，外键关联 ck_admission_category(id)" />
        </el-form-item>
        <el-form-item label="报考层次，外键关联 ck_exam_level(id)" prop="examLevelId">
          <el-input v-model="form.examLevelId" placeholder="请输入报考层次，外键关联 ck_exam_level(id)" />
        </el-form-item>
        <el-form-item label="报考科类，外键关联 ck_exam_subject(id)" prop="examSubjectId">
          <el-input v-model="form.examSubjectId" placeholder="请输入报考科类，外键关联 ck_exam_subject(id)" />
        </el-form-item>
        <el-form-item label="报考学习地点，外键关联 ck_study_location(id)" prop="studyLocationId">
          <el-input v-model="form.studyLocationId" placeholder="请输入报考学习地点，外键关联 ck_study_location(id)" />
        </el-form-item>
        <el-form-item label="学习形式，外键关联 ck_study_mode(id)" prop="studyModeId">
          <el-input v-model="form.studyModeId" placeholder="请输入学习形式，外键关联 ck_study_mode(id)" />
        </el-form-item>
        <el-form-item label="报名点信息，外键关联 ck_exam_site(id)" prop="examSiteId">
          <el-input v-model="form.examSiteId" placeholder="请输入报名点信息，外键关联 ck_exam_site(id)" />
        </el-form-item>
        <el-form-item label="邮政编码" prop="postalCode">
          <el-input v-model="form.postalCode" placeholder="请输入邮政编码" />
        </el-form-item>
        <el-form-item label="报考志愿院校名称，外键关联 ck_exam_university(id)" prop="examUniversityId">
          <el-input v-model="form.examUniversityId" placeholder="请输入报考志愿院校名称，外键关联 ck_exam_university(id)" />
        </el-form-item>
        <el-form-item label="意向专业，外键关联 ck_major(id)" prop="majorId">
          <el-input v-model="form.majorId" placeholder="请输入意向专业，外键关联 ck_major(id)" />
        </el-form-item>
        <el-form-item label="紧急联系电话" prop="emergencyContact">
          <el-input v-model="form.emergencyContact" placeholder="请输入紧急联系电话" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="CKregistration">
import { listCKregistration, getCKregistration, delCKregistration, addCKregistration, updateCKregistration } from "@/api/chengkao/CKregistration";

const { proxy } = getCurrentInstance();

const CKregistrationList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    idNumber: null,
    culturalLevelId: null,
    graduationCertificateNo: null,
    graduationTypeId: null,
    schoolId: null,
    graduationDate: null,
    occupationId: null,
    isEmployed: null,
    workLocation: null,
    workUnitName: null,
    employmentDate: null,
    outsideResidenceId: null,
    militaryServiceId: null,
    examTypeId: null,
    householdLocation: null,
    candidateFeatureId: null,
    admissionCategoryId: null,
    examLevelId: null,
    examSubjectId: null,
    studyLocationId: null,
    studyModeId: null,
    examSiteId: null,
    postalCode: null,
    examUniversityId: null,
    majorId: null,
    emergencyContact: null
  },
  rules: {
    idNumber: [
      { required: true, message: "考生身份证号，外键关联 tb_candidate(id_number)不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询考生报名信息列表 */
function getList() {
  loading.value = true;
  listCKregistration(queryParams.value).then(response => {
    CKregistrationList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    idNumber: null,
    culturalLevelId: null,
    graduationCertificateNo: null,
    graduationTypeId: null,
    schoolId: null,
    graduationDate: null,
    occupationId: null,
    isEmployed: null,
    workLocation: null,
    workUnitName: null,
    employmentDate: null,
    outsideResidenceId: null,
    militaryServiceId: null,
    examTypeId: null,
    householdLocation: null,
    candidateFeatureId: null,
    admissionCategoryId: null,
    examLevelId: null,
    examSubjectId: null,
    studyLocationId: null,
    studyModeId: null,
    examSiteId: null,
    postalCode: null,
    examUniversityId: null,
    majorId: null,
    emergencyContact: null
  };
  proxy.resetForm("CKregistrationRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加考生报名信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getCKregistration(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改考生报名信息";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["CKregistrationRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateCKregistration(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addCKregistration(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除考生报名信息编号为"' + _ids + '"的数据项？').then(function() {
    return delCKregistration(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('chengkao/CKregistration/export', {
    ...queryParams.value
  }, `CKregistration_${new Date().getTime()}.xlsx`)
}

getList();
</script>
